﻿/* ######################################## *\
 * ### Copyright (C) 2009 AJ Ravindiran ### *
\* ######################################## */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AJRavindiran.Jolt.Utilities
{
    /// <summary>
    /// Handler for all commands inputed to the console.
    /// </summary>
    public static class CommandHandler
    {
        /// <summary>
        /// Handles the inputed commands.
        /// </summary>
        /// <param name="command">The console we want to execute.</param>
        /// <param name="arguments">The arguments associated with the command.</param>
        public static void Handle(string command, params string[] arguments)
        {
            switch (command.ToLower())
            {
                case "test":
                    {
                        Console.WriteLine(RuneScape.RuneScape.GetConfigManager().General["server_name"]);
                        break;
                    }
                case "about":
                    {
                        Jolt.GetLog().WriteInfo("Jolt Environment / RuneScape Emulator");
                        Jolt.GetLog().WriteInfo("Copyright (C) 2009 AJ Ravindiran");
                        break;
                    }
                case "gc":
                    {
                        GC.Collect();
                        Jolt.GetLog().WriteInfo("Force garbage collection done.");
                        break;
                    }
                case "shutdown":
                    {
                        Jolt.ShutDown();
                        break;
                    }
                case "status":
                    {
                        Jolt.GetLog().WriteInfo("Accepted connections: " + Jolt.GetTcpConnection().AcceptedConnections);
                        Jolt.GetLog().WriteInfo("Garbage collection dumps: " + GC.CollectionCount(0));
                        break;
                    }
                case "count":
                    {
                        Jolt.GetLog().WriteDebug("Characters: " + RuneScape.RuneScape.GetCharacterManager().GetCharacters().Count);
                        Jolt.GetLog().WriteDebug("Characters queued: " + RuneScape.RuneScape.GetLoginServer().GetQueuedCharacters().Count);
                        break;
                    }
                default:
                    {
                        Jolt.GetLog().WriteWarn("Invalid command entered: " + command);
                        break;
                    }
            }
        }
    }
}
